package collecttion;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

//集合之间的操作
public class CollectionDemo4 {
    public static void main(String[] args) {
        Collection c1 = new ArrayList();//定义一个集合(可重复)
        //Collection c1 = new HashSet();//放的元素不能重复且顺序不规则
        c1.add("java");
        c1.add("c++");
        c1.add(".net");
        System.out.println("c1:"+c1);
        Collection c2 = new ArrayList<>();
        c2.add("android");
        c2.add("ios");
        c2.add("java");
        System.out.println("c2:"+c2);

        c1.addAll(c2);  //取并集,将c2并到c1中
        System.out.println("c1:"+c1);
        System.out.println("c2:"+c2);

        Collection c3 = new ArrayList();
        c3.add("c++");
        c3.add("android");
        c3.add("php");
        System.out.println("c3:"+c3);
        boolean contains = c1.containsAll(c3);
        System.out.println("c1是否包含c3所有元素："+contains);

        System.out.println("c1:"+c1);
        System.out.println("c3:"+c3);
      //  c1.retainAll(c3); //取交集,仅保留c1和c3的共有元素
        c1.removeAll(c3);//取补集,删交集,将c1和c3中共有元素删除
        System.out.println("c1:"+c1);
        System.out.println("c3:"+c3);
    }
}
